<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新版流程设计器</title>

    <link rel="stylesheet" href="linkey/bpm/newFlow/layui/css/layui.css">
    <link href="linkey/bpm/newFlow/plugings/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="linkey/bpm/newFlow/plugings/jquery-ui-1.12.1.custom/jquery-ui.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="linkey/bpm/newFlow/css/index.css">
    <link rel="stylesheet" href="linkey/bpm/newFlow/css/web.contextmenu.css">
    <link id="layuicss-laydate" rel="stylesheet"
          href="linkey/bpm/newFlow/layui/css/modules/laydate/default/laydate.css?v=5.0.9" media="all">
    <link id="layuicss-layer" rel="stylesheet"
          href="linkey/bpm/newFlow/layui/css/modules/layer/default/layer.css?v=3.1.1" media="all">
    <link id="layuicss-skincodecss" rel="stylesheet" href="linkey/bpm/newFlow/layui/css/modules/code.css" media="all">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" id="bpmu_theme" type="text/css" href="linkey/bpm/easyui/newtheme/bule/userclient.css">
    <script type="text/javascript" src="linkey/bpm/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="linkey/bpm/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="linkey/bpm/jscode/sharefunction.js"></script>
    <script type="text/javascript" src="linkey/bpm/jscode/json.js"></script>
</head>
<body>
<div id="mainDiv" title="流图绘制" style="height: 960px;">

    <iframe name="flowFrame" frameborder="0" width="100%" height="99%" id="centerFrame" scroll="no"
            src="about:blank"></iframe>

</div>
</body>

<script>
    //window.open("linkey/bpm/newFlow/Test/FlowDesigner.html");
    document.getElementById("centerFrame").setAttribute("src", "linkey/bpm/newFlow/html/load.html");
    setTimeout(function () {
        document.getElementById("centerFrame").setAttribute("src", "linkey/bpm/newFlow/html/FlowDesigner.html?Process=" + GetUrlArg("Processid"));
    }, 1000);

    var obj;

    function getObj() {
        return obj;
    }

    $(function () {

        $.ajax({
            url: "linkey/bpm/newFlow/config/config.json",
            //同步请求
            async: false,
            type: 'GET',
            success: function (data) {
                CONFIG = data;
            }
        });

        var o = {};
        var url = location.href;
        var index = url.indexOf('?');
        var params = url.substring(index + 1).split('&');
        for (var i = 0; i < params.length; i++) {
            o[params[i].split('=')[0]] = params[i].split('=')[1];
        }

        var data = getFlowJSON(GetUrlArg("Processid"));

        $("#centerFrame").attr("src", "linkey/bpm/newFlow/html/load.html");
        setTimeout(function () {
            $("#centerFrame").attr("src", "linkey/bpm/newFlow/html/FlowDesigner.html?Process=" + GetUrlArg("Processid"));
        }, 1000);
    });

    //打开流程图
    function getFlowJSON(p) {

        //如果是restful接口，把type改成对应的post（增）、delete（删）、put（改）、get（查）即可
        /*
         * 传：Processid
         * */

        var flowUrl = CONFIG.url.getFlowChartGraphic;
        flowUrl = flowUrl.replace("{processid}",p);

        $.ajax({
            url: flowUrl,
            type: 'GET',
            dataType: "json",
            success: function (data) {
                //调用成功
                $("#mainDiv").attr("processid", data.Processid);
                obj = data;
            },
            error: function (data, textStatus, errorThrown) {
                //alert("error！")
                //调用失败
            }
        });
    }

    //获取流程图
    function setFlowJSON() {

        //如果是restful接口，把type改成对应的post（增）、delete（删）、put（改）、get（查）即可
        /*
         * 传：Processid

         * */
        var obj = {
            nodeDataArray: [{
                text: '开0.0始',
                key: 'start-1',
                locTop: 600,
                locLeft: 500,
                nodeHeight: '70px',
                nodeWidth: '70px',
                bgColor: '#2175c4'
            },
                {
                    text: '填写申请单',
                    key: 'comm-1',
                    locTop: 610,
                    locLeft: 700,
                    nodeHeight: '60px',
                    nodeWidth: '110px',
                    bgColor: '#ccab26'
                },
                {
                    text: '财务部审批',
                    key: 'comm-2',
                    locTop: 460,
                    locLeft: 700,
                    nodeHeight: '60px',
                    nodeWidth: '110px',
                    bgColor: '#ccab26'
                },
                {
                    text: '总经理审批',
                    key: 'comm-3',
                    locTop: 320,
                    locLeft: 700,
                    nodeHeight: '60px',
                    nodeWidth: '110px',
                    bgColor: '#ccab26'
                },
                {
                    text: '结束',
                    key: 'end-1',
                    locTop: 310,
                    locLeft: 1100,
                    nodeHeight: '70px',
                    nodeWidth: '70px',
                    bgColor: '#ff6161'
                },
                {
                    text: '发放资金',
                    key: 'comm-4',
                    locTop: 460,
                    locLeft: 900,
                    nodeHeight: '60px',
                    nodeWidth: '110px',
                    bgColor: '#ccab26'
                },
                {
                    text: '确认资金',
                    key: 'comm-5',
                    locTop: 610,
                    locLeft: 900,
                    nodeHeight: '60px',
                    nodeWidth: '110px',
                    bgColor: '#ccab26'
                },
                {
                    text: '结束',
                    key: 'end-2',
                    locTop: 610,
                    locLeft: 1100,
                    nodeHeight: '70px',
                    nodeWidth: '70px',
                    bgColor: '#ff6161'
                }
            ],
            linkDataArray: [{
                from: 'start-1',
                to: 'comm-1',
                connectionId: 'connection-8ea7c32b80ca4981882407004ac66853'
            },
                {
                    from: 'comm-1',
                    to: 'comm-2',
                    connectionId: 'connection-e0b4c50357724b9584d96e6e769bb215'
                },
                {
                    from: 'comm-2',
                    to: 'comm-3',
                    connectionId: 'connection-5d3897669f1248c387e823177b11f30e'
                },
                {
                    from: 'comm-3',
                    to: 'end-1',
                    connectionId: 'connection-d335704ac60443bcab507b5e0b6fba86'
                },
                {
                    from: 'comm-3',
                    to: 'comm-4',
                    connectionId: 'connection-9186932d5cf3447f91fe138a435655f2'
                },
                {
                    from: 'comm-4',
                    to: 'comm-5',
                    connectionId: 'connection-ec6641781f8f43ad88cb0a22aedf0f1a'
                },
                {
                    from: 'comm-5',
                    to: 'end-2',
                    connectionId: 'connection-11368f5eb23e4b2a8aea942bcfe79705'
                }
            ]
        }

        //console.log(JSON.stringify(obj));

        var post_data = {
            "Processid": "b8b33949031c104a87083230e3d7eaea4479",
            "WF_Action": "save",
            "flowJSON": JSON.stringify(obj)

        }

        /*  $.ajax({
            url: "rest/ws/p/S018/handleFlowJSON/created",
            type: 'POST',
            //contentType: "application/json; charset=utf-8",
            //data: JSON.stringify(post_data),
            data: post_data,
            beforeSend: function(XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("sysid","bpm");
                    XMLHttpRequest.setRequestHeader("syspwd","pass");
                },
            success: function(data) {
              alert("打开返回的参数：\n 状态：" + data.Status + "\n返回信息： " + data.msg );
              console.log(data);
              //调用成功
            },
            error: function(data, textStatus, errorThrown) {
              //调用失败
            }
          });*/

    }
</script>
</html>